<template>
  <div class="content-container">
    <ImgLoder @load="showText()" :placeholder="placeholder" :src="src" />
    <div class="title" ref="title">{{ title }}</div>
    <div class="desc" ref="desc">{{ desc }}</div>
  </div>
</template>

<script>
import ImgLoder from "@/components/ImgLoder";
export default {
  components: {
    ImgLoder,
  },
  props: {
    placeholder: {
      required: true,
    },
    src: {
      required: true,
    },
    title: {
      required: true,
    },
    desc: {
      required: true,
    },
  },
  data() {
    return {
      titleWidth: 0,
      descWidth: 0,
    };
  },
  mounted() {
    this.titleWidth = this.$refs.title.clientWidth;
    this.descWidth = this.$refs.desc.clientWidth;
  },
  methods:{
      showText(){
            this.$refs.title.style.opacity=1;
            this.$refs.title.style.width=0;
            //强行渲染
            this.$refs.title.clientWidth;
            this.$refs.title.style.transition='1s';
            this.$refs.title.style.width=this.titleWidth+'px';
            //
             this.$refs.desc.style.opacity=1;
            this.$refs.desc.style.width=0;
            //强行渲染
            this.$refs.desc.clientWidth;
            this.$refs.desc.style.transition='2s';
            this.$refs.desc.style.width=this.descWidth+'px';
      }
  }
};
</script>

<style lang="less" scoped>
.content-container {
  width: 100%;
  height: 100%;
  position: relative;
  .desc,
  .title {
    color: #fff;
    position: absolute;
    left: 30px;
    letter-spacing: 3px;
    white-space: nowrap;
    overflow: hidden;
    opacity: 0;
  }
  .title {
    top: 43%;
    transform: translate(0, -30%);
    font-size: 2em;
  }
  .desc {
    top: 53%;
    transform: translate(0, -50%);
    font-size: 1.2em;
  }
}
</style>